<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/webpage/include/taglib.jsp"%>
<%@ attribute name="path" type="java.lang.String" required="true" description="输入框"%>
<%@ attribute name="value" type="java.lang.String" required="true" description="输入框"%>
<%--
type:
    all: 允许上传所有文件
    file: 只允许上传所有非可执行文件（排除.sql,.exe,.jsp等等后缀类型的文件）
    image: 只允许上传图片
    audio: 只允许上传音频文件
    video: 只允许上传视频文件
    office: 只允许上传文档类型

    指定type参数时，将忽略allowedExtensions 和 deniedExtensions参数，请勿配置。
--%>
<%--<%@ attribute name="type" type="java.lang.String" required="false" description="*,files、images、video、audio、office"%>--%>
<%--<%@ attribute name="uploadPath" type="java.lang.String" required="true" description="文件上传路径"%>--%>
<%@ attribute name="fileNumLimit" type="java.lang.String" required="false" description="是否允许多选"%>
<%@ attribute name="fileSizeLimit" type="java.lang.String" required="false" description="文件大小"%>
<%@ attribute name="readonly" type="java.lang.Boolean" required="false" description="是否查看模式"%>
<%@ attribute name="divName" type="java.lang.String" required="false" description="区别id"%>

<%--
allowedExtensions:允许上传的文件类型
deniedExtensions： 禁止上传的文件类型
--%>
<%@ attribute name="allowedExtensions" type="java.lang.String"  required="false" description="允许的文件类型"%>
<%--7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip--%>
<%--bmp,gif,jpeg,jpg,png--%>

<div class="input-group" style="width:100%">
    <span style="height: 100%;" class="form-control" id="uploadFile${divName}">
    </span>
</div>
<script type="text/javascript">
    var classFileLen;
    $(function () {
        var valueList = ${value}
        var appendStr1 = "";
        classFileLen = valueList.length;
        for(var i = 0; i < valueList.length; i++){
            var appendStr = "<div style=\"float: left;text-align: center;height: auto;width: 95px;margin-right: 5px;\">";
            appendStr = appendStr + "<input id=\"${path}_id" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].id\"  value=\""+valueList[i].id+"\"/>";
            appendStr = appendStr + "<input id=\"${path}_fileTitle" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].fileTitle\"  value=\""+valueList[i].adjunctClass.name+"\"/>";
            appendStr = appendStr + "<input id=\"${path}_objectId" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].objectId\"  value=\""+valueList[i].objectId+"\"/>";
            appendStr = appendStr + "<input id=\"${path}_dataId" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].dataId\"  value=\""+valueList[i].dataId+"\"/>";
            appendStr = appendStr + "<input id=\"${path}_classId" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].adjunctClass.id\"  value=\""+valueList[i].adjunctClass.id+"\"/>";
            appendStr = appendStr + "<input id=\"${path}_yesno" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].adjunctClass.yesno\"  value=\""+valueList[i].adjunctClass.yesno+"\"/>";
            appendStr = appendStr + "<input id=\"${path}_classFile" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].classFile\"  value=\""+valueList[i].classFile+"\"/>";
            appendStr = appendStr + "<input id=\"${path}_delFlag" + i + "\" type=\"hidden\" name=\"${path}[" + i + "].delFlag\"  value=\"0\"/>";
            appendStr = appendStr + "<img id=\"" + valueList[i].id + "\" title=\"" + valueList[i].adjunctClass.name +
                "\" style=\"cursor:pointer;width: auto;height: 50px;max-width: 100%;max-height: 100%\" " +
                "src=\"${ctxStatic}/common/images/" + valueList[i].adjunctClass.imagee + "\" onclick=\"FileDialogOpen(\'${path}\',\'" + valueList[i].adjunctClass.uploadPath+"\',\'" + valueList[i].adjunctClass.typeName + "\',\'" + i + "\',\'" + valueList[i].adjunctClass.name + "\')\">";
            var num = 0;
            if(valueList[i].classFile != ''){
                num = valueList[i].classFile.split("|").length
            }
            if(num >0){
                appendStr = appendStr + "<h3 id=\"" + valueList[i].adjunctClass.name + "_h3\" style=\"font-size: 15px;color: rgba(152,154,154,0.98);margin-top: 5px;margin-bottom: 0px;\">"
                if(valueList[i].adjunctClass.yesno == "4395a1ad0cf74146b1fc8e45b379c7c1")  {
                    appendStr = appendStr + "<font color=\"red\">*</font>";
                }
                appendStr = appendStr + valueList[i].adjunctClass.name + "[<span style='color: red'>" + num + "</span>]</h3>";
            }else {
                appendStr = appendStr + "<h3 id=\"" + valueList[i].adjunctClass.name + "_h3\" style=\"font-size: 15px;color: rgba(152,154,154,0.98);margin-top: 5px;margin-bottom: 0px;\">"
                if(valueList[i].adjunctClass.yesno == "4395a1ad0cf74146b1fc8e45b379c7c1")  {
                    appendStr = appendStr + "<font color=\"red\">*</font>";
                }
                appendStr = appendStr + valueList[i].adjunctClass.name + "[" + num + "]</h3>";
            }
            appendStr = appendStr + "</div>"
            appendStr1 = appendStr1 + appendStr;
        }
        $("#uploadFile${divName}").append(appendStr1);
    })
    function FileDialogOpen(id,uploadPath,type,idx,name) {
        var currentFileValues = $("input[name='${path}["+idx+"].classFile']").val();
        /*jp.open({
            type: 2,
            area: ['800px', '800px'],
            title:"上传文件",
            auto:true,
            content: "${ctx}/tag/fileUploadNew?fileValues="+encodeURIComponent(currentFileValues)+"&uploadPath="+uploadPath+"&type="+type+"&readonly=${readonly}"
            +"&fileNumLimit=${fileNumLimit}"+"&fileSizeLimit=${fileSizeLimit}"+"&allowedExtensions=${allowedExtensions}"+"&deniedExtensions=${deniedExtensions}",
            cancel: function(index, layero){
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var fileNames =iframeWin.contentWindow.getUploadFileNames();//调用保存事件
                var fileValues =iframeWin.contentWindow.getUploadFileValues();//调用保存事件
                <%--$("#${path}"+"["+idx+"]").val(fileValues);--%>
                $("input[name='${path}["+idx+"].classFile']").val(fileValues);
                var fileNamesArr = fileNames.split(",");
                if(fileNamesArr != ""){
                    var fileValuesArr = fileValues.split("|");
                    $("#"+name+"_h3").html(name+"[<span style='color: red'>"+fileValuesArr.length+"</span>]");
                }else {
                    $("#"+name+"_h3").html(name+"[0]");
                }

            }
        });*/
        var classFiles = $("input[name='${path}["+idx+"].classFile']").val();
        jp.open({
            type: 2,
            area: ['800px', '800px'],
            title:"上传文件",
            auto:true,
            content: "${ctx}/tag/fileUploadNew?fileValues="+encodeURIComponent(classFiles)+"&uploadPath="+uploadPath+"&type="+type+"&readonly=${readonly}"
                +"&fileNumLimit=${fileNumLimit}"+"&fileSizeLimit=${fileSizeLimit}"+"&allowedExtensions=${allowedExtensions}"+"&deniedExtensions=${deniedExtensions}",
            cancel: function(index, layero){
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var fileNames =iframeWin.contentWindow.getUploadFileNames();//调用保存事件
                var fileValues =iframeWin.contentWindow.getUploadFileValues();//调用保存事件
                <%--$("#${path}"+"["+idx+"]").val(fileValues);--%>
                $("input[name='${path}["+idx+"].classFile']").val(fileValues);
                var fileNamesArr = fileNames.split(",");
                if(fileNamesArr != ""){
                    var fileValuesArr = fileValues.split("|");
                    $("#"+name+"_h3").html("<font color=\"red\">*</font>"+name+"[<span style='color: red'>"+fileValuesArr.length+"</span>]");
                }else {
                    $("#"+name+"_h3").html("<font color=\"red\">*</font>"+name+"[0]");
                }

            }
        });
    }

</script>
